package 常用类.Array类;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class FanXing {
    public static void main(String[] args) {
        //String型
        ArrayList<String> list= new ArrayList<String>();
        list.add("hello");
        list.add("20");
        list.add("jiazhong");
        for (String str:list){
            System.out.println(str);
        }
    }

    //int型
    public static void numList(){
        ArrayList<Integer> num = new ArrayList<Integer>();
        num.add(1);
        num.add(3);
        System.out.println(num);
    }

    public static void Array() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        List<String> list=new ArrayList<>();
        list.add("hello");
        list.add("abc");
        list.add("xyz");

        //在运行期向集合中添加元素
        Class listCla=list.getClass();
        Method addMethod=listCla.getDeclaredMethod("add",String.class);
        addMethod.invoke(listCla,Integer.valueOf("20"));
        System.out.println(list);
    }
}
